//
//  StatusRetweetedView.m
//  Weibo
//
//  Created by Anasue on 9/16/15.
//  Copyright (c) 2015 Anasue. All rights reserved.
//

#import "StatusRetweetedView.h"
#import "Status.h"
#import "User.h"
#import "StatusRetweetedViewFrame.h"
#import "StatusPhotosView.h"
#import "StatusRetweetedToolBar.h"
#import "StatusDetailViewController.h"
#import "StatusLabel.h"


@interface StatusRetweetedView ()
/**  昵称 */
//@property (nonatomic, weak) UILabel *nameLabel;
/** 正文 */
@property (nonatomic, weak) UILabel *textLabel;
/** 配图 */
@property (nonatomic, weak) StatusPhotosView *photosView;
@property (nonatomic, weak) StatusRetweetedToolBar *toolBar;

@end

@implementation StatusRetweetedView

- (id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        self.userInteractionEnabled = YES;
        self.image = [UIImage resizeImage:@"timeline_retweet_background"];
        //创建昵称
//        UILabel *nameLabel = [[UILabel alloc]init];
//        nameLabel.textColor = Color(74, 102, 105);
//        nameLabel.font = StatusRetweetedNameFont;
//        [self addSubview:nameLabel];
//        self.nameLabel = nameLabel;
        
        //创建正文
        StatusLabel *textLabel = [[StatusLabel alloc]init];
//        textLabel.numberOfLines = 0;
//        textLabel.font = StatusRetweetedTextFont;
        [self addSubview:textLabel];
        self.textLabel = textLabel;
        
        //配图相册
        StatusPhotosView *photosView = [[StatusPhotosView alloc]init];
        [self addSubview:photosView];
        self.photosView = photosView;
        //工具条
        StatusRetweetedToolBar *toolBar = [[StatusRetweetedToolBar alloc]init];
        [self addSubview:toolBar];
        self.toolBar = toolBar;
    }
    return self;
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    UITabBarController *tabBarController = (UITabBarController *)[UIApplication sharedApplication].keyWindow.rootViewController;
    UINavigationController *nav = tabBarController.selectedViewController;
    StatusDetailViewController *detailVc = [[StatusDetailViewController alloc]init];
    detailVc.status = self.retweetedViewFrame.retweetedStatus;
    [nav pushViewController:detailVc animated:YES];
}

- (void)setRetweetedViewFrame:(StatusRetweetedViewFrame *)retweetedViewFrame
{
    _retweetedViewFrame = retweetedViewFrame;
    self.frame = retweetedViewFrame.frame;    
    Status *retweetedStatus = retweetedViewFrame.retweetedStatus;
//    User *user = retweetedStatus.user;
//    self.nameLabel.text = [NSString stringWithFormat:@"@%@",user.name];
//    self.nameLabel.text = user.name;
//    self.nameLabel.frame = retweetedViewFrame.nameFrame;
//    self.textLabel.text = retweetedStatus.text;
    self.textLabel.attributedText = retweetedStatus.attributedText;
    self.textLabel.frame = retweetedViewFrame.textFrame;
    if (retweetedStatus.pic_urls.count) { // 有配图
        self.photosView.frame = retweetedViewFrame.photosFrame;
        self.photosView.pic_urls = retweetedStatus.pic_urls;
        self.photosView.hidden = NO;
    } else {
        self.photosView.hidden = YES;
    }
}



@end
